package com.woniuxy.test06;

import org.junit.Test;

import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

/**
 * @Author author
 * @Create 2023-09-15 9:46
 */

//Coffee
//MilkCoffee
//SugarCoffee
//SaltCoffee
//各种组合...
//Milk+Sugar
//Milk+Salt
//...类爆炸

//是你（继承）还有你（包含），一切拜托你
class Coffee{
    public String getCoffee(){
        return "coffee";
    }
}

class MilkCoffee extends Coffee{
    Coffee coffee;

    public MilkCoffee(Coffee coffee) {
        this.coffee = coffee;
    }

    public String getCoffee(){
        return "milk-"+coffee.getCoffee();
    }
}
class SugarCoffee extends Coffee{
    Coffee coffee;

    public SugarCoffee(Coffee coffee) {
        this.coffee = coffee;
    }

    public String getCoffee(){
        return "sugar-"+coffee.getCoffee();
    }
}
class SaltCoffee extends Coffee{
    Coffee coffee;

    public SaltCoffee(Coffee coffee) {
        this.coffee = coffee;
    }

    public String getCoffee(){
        return "salt-"+coffee.getCoffee();
    }
}

public class MyTest {

    @Test
    public void test01() throws IOException {
//        Coffee coffee1 = new Coffee();
//        System.out.println(coffee1.getCoffee());
//        MilkCoffee coffee2 = new MilkCoffee(coffee1);
//        System.out.println(coffee2.getCoffee());
//
//        SugarCoffee coffee3 = new SugarCoffee(coffee2);
//        System.out.println(coffee3.getCoffee());

        MilkCoffee coffee = new MilkCoffee(new SugarCoffee(new SaltCoffee(new Coffee())));
        System.out.println(coffee.getCoffee());

        //IO
        //字节流
        //字符流：字节流+编码
        //BufferedXxx:原来的流+缓存区
        new BufferedWriter( new OutputStreamWriter(new FileOutputStream("aaa.txt")));
    }

}


